package com.hao.mydownloadlist.service.utils;

import com.hao.mydownloadlist.event.DownloadEvent;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hao on 16/11/21.
 */
public class DownloadList {

    private static class DownloadListHolder {
        static DownloadList downloadList = new DownloadList();
    }

    public static DownloadList getInstance() {
        return DownloadListHolder.downloadList;
    }

    private List<DownloadEvent> downloadBeanList;


    public List<DownloadEvent> getDownloadBeanList() {
        return downloadBeanList;
    }

    public void setDownloadBeanList(List<DownloadEvent> downloadBeanList) {
        this.downloadBeanList = downloadBeanList;
    }

    //添加对应的下载对象
    public void addObject(DownloadEvent downloadEvent) {
        if (ListUtils.isEmpty(downloadBeanList))
            downloadBeanList = new ArrayList<>();
        downloadBeanList.add(downloadEvent);
    }

    /**
     * 获取集合的长度
     */

    public int getCount() {
        if (ListUtils.isEmpty(downloadBeanList))
            return 0;
        return downloadBeanList.size();
    }


    /**
     * 清除相应的下载集合
     */
    public void clearList() {
        if (downloadBeanList != null && downloadBeanList.size() > 0)
            downloadBeanList.clear();
        downloadBeanList = null;
    }
}
